package com.glm.fruit.service;

import com.glm.fruit.entity.CartItem;

import java.util.ArrayList;
import java.util.List;

public class ShoppingCart {
    private List<CartItem> items = new ArrayList<CartItem>();
    private List<Promotion> promotions = new ArrayList<Promotion>();

    public void addItem(CartItem item) {
        items.add(item);
    }

    public void addPromotion(Promotion promotion) {
        promotions.add(promotion);
    }

    public double calculateTotal() {
        double total = 0;
        for (CartItem item : items) {
            total += item.getSubtotal();
        }
        for (Promotion promo : promotions) {
            total = promo.apply(items, total);
        }
        return total;
    }
}
